package com.zn.service.impl;

import com.zn.entity.AppCustomer;
import com.zn.entity.CustomerBankInfo;
import com.zn.mapper.AppCustomerMapper;
import com.zn.mapper.CustomerBankInfoMapper;
import com.zn.service.BankInfoService;
import com.zn.util.UUIDUtils;
import com.zn.vo.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

/**
 * Created by yinjiawei on 2018/8/2.
 */
@Service
public class BankInfoServiceImpl implements BankInfoService {
    private static final Logger LOGGER = LoggerFactory.getLogger(BankInfoServiceImpl.class);
    @Autowired
    private CustomerBankInfoMapper customerBankInfoMapper;
    @Autowired
    private AppCustomerMapper appCustomerMapper;
    @Override
    public ResponseEntity<Message> customerTiedCard(CustomerBankInfo customerBankInfoDto) {
        AppCustomer appCustomer=appCustomerMapper.selectByPrimaryKey(customerBankInfoDto.getCustomerId());
        if(appCustomer==null){
            //用户不存在
            return ResponseEntity.ok(Message.CUSTOMER_NOT_EXIST);
        }
        CustomerBankInfo customerBankInfo=customerBankInfoMapper.selectByCustomerIdAndBankNo(customerBankInfoDto.getCustomerId(), customerBankInfoDto.getBankNo());
        if(customerBankInfo!=null){
            //重复绑卡
            return ResponseEntity.ok(Message.TIED_CARD_REPEAT);
        }
        customerBankInfoDto.setBankInfoId(UUIDUtils.getUuid());
        customerBankInfoMapper.insertSelective(customerBankInfoDto);
        return ResponseEntity.ok(Message.REQ_SUCCESS);
    }
}
